import Vue from 'vue'
import VueRouter from 'vue-router'
// 引入一级路由
import Home from "../views/Home.vue"
import Login from "../views/Login.vue"
import Registry from "../views/Registry.vue"
import Addsite from "../views/Addsite.vue"
Vue.use(VueRouter)

const routes = [
  // 一级路由重定向
  {
    path: '/',
    redirect: "/home"
  },
  {
    path: '/home',
    name: 'Home',
    meta:{
      title: '首页'
    },
    component: Home,
  },
  {
    path: '/login',
    name: 'Login',
    meta:{
      title: '登录'
    },
    component: Login
  },
  {
    path: '/registry',
    name: 'Registry',
    meta:{
      title: '注册'
    },
    component: Registry
  },
  {
    path: '/addsite/:type',
    name: 'Addsite',
    meta:{
      title: '新增地址'
    },
    component: Addsite
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  document.title = to.meta?.title
  next();
})

export default router
